/*
 * XSDDate.java
 *
 * Created on April 22, 2007, 10:49 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.xeerkat.agent.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author alex
 */
public class XSDDate
{
   
   /** Creates a new instance of XSDDate */
   private XSDDate()
   {
   }
   
   public static DateFormat getDateAndTimeFormatter() {
      return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
   }
   
   public static String toString(Date d) {
      DateFormat format = getDateAndTimeFormatter();
      String v = format.format(d);
      return v.substring(0,22)+':'+v.substring(22);
   }
   
   public static Date fromString(String value)
      throws ParseException
   {
      String v = value.substring(0,22)+value.substring(23);
      DateFormat format = getDateAndTimeFormatter();
      return format.parse(v);
   }
   
}
